﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Net;
using System.Xml;
using System.Text;
using System.IO;
namespace LHWebApp.Json
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class JsonGetVehicleCurrentInfoList : IHttpHandler
    {
        //houruixian 2018.07.13 
        List<CurrentVehicleEntity> currentVehicleList = new List<CurrentVehicleEntity>();
        CurrentVehicleEntity currentVehicle = null;

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string op = context.Request.Params["op"];
            switch (op)
            {
                case "GetLoginInfoSelectOptions":
                    GetLoginInfoSelectOptions(context);
                    break;
                case "GetGroupList":
                    GetGroupList(context);
                    break;
                case "carListCurrentVehicle":
                    carListCurrentVehicle(context);
                    break;
                case "GetVideoLoginInfo":
                    getVideoLoginInfo(context);
                    break;
                case "GetVehicleCurrentInfoDistrict":
                    GetVehicleCurrentInfoDistrict(context);
                    break;
                case "GetVehicleCurrentInfoCity":
                    GetVehicleCurrentInfoCity(context);
                    break;
                case "GetVideoBySimcard_No":
                    GetVideoBySimcard_No(context);
                    break;
                case "GetVideoByLoaction":
                    GetVideoByLoaction(context);
                    break;

                case "GetPlaceCLC":
                    getPlaceCLC(context);
                    break;
                case "GetPlaceNCD":
                    getPlaceNCD(context);
                    break;
                case "GetPlaceZZZ":
                    getPlaceZZZ(context);
                    break;
                case "GetPlaceCY":
                    getPlaceCY(context);
                    break;
                case "GetPlaceXQCY":
                    getPlaceXQCY(context);
                    break;
                default:
                    context.Response.Write("{success: false}");
                    break;
            }
        }
        private void GetVideoByLoaction(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string lng = context.Request.Params["lng"];
            string lat = context.Request.Params["lat"];
            //if (string.IsNullOrEmpty(carNum))
            //{
            //    context.Response.Write("{success: false}");
            //}
            //else
            //{
            try
            {
                DataTable dt = LHWebApp.Services.GetVideoByLoaction(lng, lat).Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        jsonHelp.AddItem("ICCID", dr[0].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
            //}
        }
        private void GetVideoBySimcard_No(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string carNum = context.Request.Params["carNum"];
            if (string.IsNullOrEmpty(carNum))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVideoBySimcard_No(carNum).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("ICCID", dr[0].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void getVideoLoginInfo(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVideoLoginInfo(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("id", dr[0].ToString());
                            jsonHelp.AddItem("pword", dr[1].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void GetGroupList(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string currentService = context.Request.Params["currentService"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetClientInfoList(currentService, clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            if (currentService == "5")
                            {
                                jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                                jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NAME"].ToString());
                                jsonHelp.ItemOk();
                            }
                            else
                            {
                                jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                                jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NO"].ToString());
                                jsonHelp.ItemOk();
                            }

                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }

        private void GetVehicleCurrentInfoCity(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string currentService = context.Request.Params["currentService"];

            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoCity(currentService, clientNo).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("type", dr[0].ToString());
                            jsonHelp.AddItem("carCountOnline", dr[1].ToString());
                            jsonHelp.AddItem("carCountAll", dr[2].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void GetVehicleCurrentInfoDistrict(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string currentService = context.Request.Params["currentService"];

            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoDistrict(currentService, clientNo).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("type", dr[0].ToString());
                            jsonHelp.AddItem("carCountOnline", dr[1].ToString());
                            jsonHelp.AddItem("carCountAll", dr[2].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        private void GetVehicleCurrentInfoSynthetical(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            string tab = context.Request.Params["tab"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.GetVehicleCurrentInfoSynthetical(clientNo, tab).Tables[0];//2019.09.20 zx

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            jsonHelp.AddItem("type", dr[0].ToString());
                            jsonHelp.AddItem("carCountOnline", dr[1].ToString());
                            jsonHelp.AddItem("carCountAll", dr[2].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }




        //private void carListCurrentVehicle(HttpContext context)
        //{
        //    context.Response.ContentType = "text/plain";
        //    string clientNo = context.Request.Params["clientNo"];
        //    string carType = context.Request.Params["carType"];//2018.07.23 houruixian 车辆类型
        //    string licensePlate = context.Request.Params["licensePlate"];//2019.09.20 zx 车辆牌号
        //    string carGroup = context.Request.Params["carGroup"];//2019.09.20 zx 车辆分组
        //    string carStatus = context.Request.Params["status"];//2019.09.20 zx 车辆状态
        //    string currentService = context.Request.Params["currentService"];

        //    if (string.IsNullOrEmpty(clientNo))
        //    {
        //        context.Response.Write("{success: false}");
        //    }
        //    else
        //    {
        //        try
        //        {
        //            DataTable dt = null;
        //            DataSet ds = LHWebApp.Services.GetVehicleCurrentInfoList(currentService, clientNo, licensePlate, carGroup, carStatus, carType);//2019.09.20 zx
        //            if (currentService == "6")
        //            {
        //                dt = ds.Tables[1];
        //            }
        //            else
        //            {
        //                dt = ds.Tables[0];
        //            }
        //            JSONHelper jsonHelp = new JSONHelper();
        //            jsonHelp.success = true;
        //            jsonHelp.totlalCount = dt.Rows.Count;
        //            if (jsonHelp.totlalCount == 0)
        //            {
        //                context.Response.Write("{success: true}");
        //            }
        //            else
        //            {
        //                foreach (DataRow dr in dt.Rows)
        //                {
        //                    if (currentService == "1") { }
        //                    //jsonHelp.AddItem("ID", dr[0].ToString());
        //                    jsonHelp.AddItem("Name", dr["POINTNAME"].ToString());
        //                    //jsonHelp.AddItem("LOACTION", dr[1].ToString());
        //                    //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
        //                    //jsonHelp.AddItem("TYPE", dr[3].ToString());
        //                    //jsonHelp.AddItem("SIZE", dr[4].ToString());
        //                    jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
        //                    jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
        //                    jsonHelp.ItemOk();
        //                }
        //                context.Response.Write(jsonHelp.ToString());
        //            }
        //        }
        //        catch (Exception)
        //        {
        //            context.Response.Write("{success: false}");
        //        }
        //    }
        //}

        private void carListCurrentVehicle(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string carType = context.Request.Params["carType"];//2018.07.23 houruixian 车辆类型
            string licensePlate = context.Request.Params["licensePlate"];//2019.09.20 zx 车辆牌号
            string carGroup = context.Request.Params["carGroup"];//2019.09.20 zx 车辆分组
            string carStatus = context.Request.Params["status"];//2019.09.20 zx 车辆状态
            string clientNo = context.Request.Params["clientNo"];

            string currentService = context.Request.Params["currentService"];

            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = null;

                    /*
                    if (carType != "" && carType != "全部")
                    {
                        dt = LHWebApp.Services.GetVehicleCurrentInfoList(clientNo,carType).Tables[0];
                    }
                    else
                    {
                       
                     dt = LHWebApp.Services.GetVehicleCurrentInfoList(clientNo).Tables[0];
                     
                    }
                     * */
                    DataSet ds = LHWebApp.Services.GetVehicleCurrentInfoList(currentService, clientNo, licensePlate, carGroup, carStatus, carType);//2019.09.20 zx
                    //if (currentService == "6") { 
                    //    dt = ds.Tables[1];
                    //}
                    //else
                    //{
                        dt = ds.Tables[0];
                    //}

                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {

                        foreach (DataRow dr in dt.Rows)
                        {
                            currentVehicle = new CurrentVehicleEntity();
                            if (currentService == "6")
                            {
                                currentVehicle.VID = dr["编号"].ToString();
                                currentVehicle.ClientNo = dr["组织编号"].ToString();
                                currentVehicle.ClientName = dr["组织名称"].ToString();
                                currentVehicle.LicensePlate = dr["名称"].ToString();
                                currentVehicle.CardNo = dr["通讯卡号"].ToString();
                                currentVehicle.CarType = dr["类型"].ToString();
                                currentVehicle.GpsTime = dr["最终定位时间"].ToString();
                                currentVehicle.Lng = dr["经度"].ToString();
                                currentVehicle.Lat = dr["纬度"].ToString();
                                currentVehicle.Speed = dr["速度"].ToString();
                                currentVehicle.Direction = dr["方向"].ToString();
                                
                                
                                currentVehicle.Status = dr["状态"].ToString();
                                currentVehicle.Location = dr["位置"].ToString();

                                currentVehicle.section1 = dr["性别"].ToString();
                                currentVehicle.section2 = dr["心跳"].ToString();
                                currentVehicle.section3 = dr["电话"].ToString();
                                currentVehicle.section14 = dr["生日"].ToString();
                                currentVehicle.section15 = dr["入职时间"].ToString();
                                currentVehicle.section4 = dr["所属清扫队"].ToString();
                                currentVehicle.section5 = dr["所属班组"].ToString();
                                currentVehicle.section6 = dr["负责区域"].ToString();
                                currentVehicle.section7 = dr["设备类型"].ToString();


                                currentVehicle.section8 = dr["打卡情况"].ToString();
                                currentVehicle.section9 = dr["油量"].ToString();
                                currentVehicle.section10 = dr["作业状态"].ToString();
                                currentVehicle.section11 = dr["扩展状态"].ToString();
                                currentVehicle.section12 = dr["指令应答"].ToString();
                                currentVehicle.section13 = dr["唯一标识码"].ToString();



                                currentVehicle.LngOffset = dr["负责维保公厕"].ToString();
                                currentVehicle.LatOffset = dr["正在维保公厕"].ToString();
                                //currentVehicle.TemperatureRT = dr["TemperatureRT"].ToString();

                                DateTime datetime = DateTime.ParseExact(dr["最终定位时间"].ToString(), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                                TimeSpan difTime = DateTime.Now - datetime;
                                if (difTime.TotalMinutes > 3.0)
                                {
                                    currentVehicle.Status = "6";
                                }
                                else
                                {
                                    currentVehicle.Status = "0";
                                }
                            }
                            else if (currentService == "5")
                            {
                                currentVehicle.VID = dr["编号"].ToString();
                                currentVehicle.ClientNo = dr["组织编号"].ToString();
                                currentVehicle.ClientName = dr["组织名称"].ToString();
                                currentVehicle.LicensePlate = dr["名称"].ToString();
                                currentVehicle.CardNo = dr["通讯卡号"].ToString();
                                currentVehicle.Lng = dr["经度"].ToString();
                                currentVehicle.Lat = dr["纬度"].ToString();
                                currentVehicle.Speed = dr["速度"].ToString();
                                currentVehicle.Direction = dr["方向"].ToString();
                                currentVehicle.GpsTime = dr["最终定位时间"].ToString();
                                currentVehicle.CarType = dr["类型"].ToString();
                                currentVehicle.Status = dr["状态"].ToString();
                                currentVehicle.Location = dr["位置"].ToString();

                                currentVehicle.section1 = dr["性别"].ToString();
                                currentVehicle.section2 = dr["心跳"].ToString();
                                currentVehicle.section3 = dr["电话"].ToString();
                                currentVehicle.section4 = dr["所属镇"].ToString();
                                currentVehicle.section5 = dr["所属村"].ToString();
                                currentVehicle.section6 = dr["负责区域"].ToString();
                                currentVehicle.section7 = dr["设备类型"].ToString();


                                currentVehicle.section8 = dr["打卡情况"].ToString();
                                currentVehicle.section9 = dr["油量"].ToString();
                                currentVehicle.section10 = dr["作业状态"].ToString();
                                currentVehicle.section11 = dr["扩展状态"].ToString();
                                currentVehicle.section12 = dr["指令应答"].ToString();
                                currentVehicle.section13 = dr["唯一标识码"].ToString();
                                currentVehicle.section14 = dr["生日"].ToString();
                                currentVehicle.section15 = dr["入职时间"].ToString();
                                currentVehicle.section16 = dr["数据类型"].ToString();


                                currentVehicle.LngOffset = dr["CurrentNum"].ToString();
                                currentVehicle.LatOffset = dr["ALLNUM"].ToString();
                                //currentVehicle.TemperatureRT = dr["TemperatureRT"].ToString();

                                DateTime datetime = DateTime.ParseExact(dr["最终定位时间"].ToString(), "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
                                TimeSpan difTime = DateTime.Now - datetime;
                                if (difTime.TotalMinutes > 3.0)
                                {
                                    currentVehicle.Status = "6";
                                }
                                else
                                {
                                    currentVehicle.Status = "0";
                                }
                            }
                            else
                            {
                                currentVehicle.VID = dr["VID"].ToString();
                                currentVehicle.ClientNo = dr["ClientNo"].ToString();
                                currentVehicle.ClientName = dr["ClientName"].ToString();
                                currentVehicle.LicensePlate = dr["LicensePlate"].ToString();
                                currentVehicle.CardNo = dr["CardNo"].ToString();
                                currentVehicle.Lng = dr["Lng"].ToString();
                                currentVehicle.Lat = dr["Lat"].ToString();
                                currentVehicle.Speed = dr["Speed"].ToString();
                                currentVehicle.Direction = dr["Direction"].ToString();
                                currentVehicle.GpsTime = dr["GpsTime"].ToString();
                                currentVehicle.CarType = dr["CarType"].ToString();
                                currentVehicle.Status = dr["Status"].ToString();
                                currentVehicle.Location = dr["Location"].ToString();
                                currentVehicle.LngOffset = dr["CurrentNum"].ToString();
                                currentVehicle.LatOffset = dr["ALLSUM"].ToString();
                                currentVehicle.TemperatureRT = dr["TemperatureRT"].ToString();
                            }


                            currentVehicleList.Add(currentVehicle);

                        }
                        AdjustBaiduLongLat(currentVehicleList);
                        for (int i = 0; i < currentVehicleList.Count; i++)
                        {
                            jsonHelp.AddItem("VID", currentVehicleList[i].VID);
                            jsonHelp.AddItem("ClientNo", currentVehicleList[i].ClientNo);
                            jsonHelp.AddItem("ClientName", currentVehicleList[i].ClientName);
                            jsonHelp.AddItem("LicensePlate", currentVehicleList[i].LicensePlate);
                            jsonHelp.AddItem("CardNo", currentVehicleList[i].CardNo);

                            jsonHelp.AddItem("Lng", currentVehicleList[i].Lng);
                            jsonHelp.AddItem("Lat", currentVehicleList[i].Lat);


                            jsonHelp.AddItem("Speed", currentVehicleList[i].Speed);
                            jsonHelp.AddItem("Direction", currentVehicleList[i].Direction);
                            jsonHelp.AddItem("GpsTime", currentVehicleList[i].GpsTime);
                            jsonHelp.AddItem("CarType", currentVehicleList[i].CarType);
                            jsonHelp.AddItem("Status", currentVehicleList[i].Status);
                            jsonHelp.AddItem("Location", currentVehicleList[i].Location);
                            jsonHelp.AddItem("LngOffset", currentVehicleList[i].LngOffset);
                            jsonHelp.AddItem("LatOffset", currentVehicleList[i].LatOffset);
                            jsonHelp.AddItem("TemperatureRT", currentVehicleList[i].TemperatureRT);

                            jsonHelp.AddItem("ssection1", currentVehicleList[i].section1);
                            jsonHelp.AddItem("ssection2", currentVehicleList[i].section2);
                            jsonHelp.AddItem("ssection3", currentVehicleList[i].section3);
                            jsonHelp.AddItem("ssection4", currentVehicleList[i].section4);
                            jsonHelp.AddItem("ssection5", currentVehicleList[i].section5);
                            jsonHelp.AddItem("ssection6", currentVehicleList[i].section6);
                            jsonHelp.AddItem("ssection7", currentVehicleList[i].section7);
                            jsonHelp.AddItem("ssection8", currentVehicleList[i].section8);
                            jsonHelp.AddItem("ssection9", currentVehicleList[i].section9);
                            jsonHelp.AddItem("ssection10", currentVehicleList[i].section10);
                            jsonHelp.AddItem("ssection11", currentVehicleList[i].section11);
                            jsonHelp.AddItem("ssection12", currentVehicleList[i].section12);
                            jsonHelp.AddItem("ssection13", currentVehicleList[i].section13);
                            jsonHelp.AddItem("ssection14", currentVehicleList[i].section14);
                            jsonHelp.AddItem("ssection15", currentVehicleList[i].section15);
                            jsonHelp.AddItem("ssection16", currentVehicleList[i].section16);
                            jsonHelp.AddItem("ssection17", currentVehicleList[i].section17);
                            jsonHelp.AddItem("ssection18", currentVehicleList[i].section18);

                            jsonHelp.ItemOk();
                        }


                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }



        //农村点
        private void getPlaceNCD(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceNCD(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["POINTNAME"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //处理厂
        private void getPlaceCLC(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceCLC(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //中转站
        private void getPlaceZZZ(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceZZZ(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //餐饮
        private void getPlaceCY(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            if (string.IsNullOrEmpty(clientNo))
            {
                context.Response.Write("{success: false}");
            }
            else
            {
                try
                {
                    DataTable dt = LHWebApp.Services.getPlaceCY(clientNo).Tables[0];
                    JSONHelper jsonHelp = new JSONHelper();
                    jsonHelp.success = true;
                    jsonHelp.totlalCount = dt.Rows.Count;
                    if (jsonHelp.totlalCount == 0)
                    {
                        context.Response.Write("{success: true}");
                    }
                    else
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            //jsonHelp.AddItem("ID", dr[0].ToString());
                            jsonHelp.AddItem("Name", dr["Name"].ToString());
                            //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                            //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                            //jsonHelp.AddItem("TYPE", dr[3].ToString());
                            //jsonHelp.AddItem("SIZE", dr[4].ToString());
                            jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                            jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                            jsonHelp.ItemOk();
                        }
                        context.Response.Write(jsonHelp.ToString());
                    }
                }
                catch (Exception)
                {
                    context.Response.Write("{success: false}");
                }
            }
        }
        //小区厨余
        private void getPlaceXQCY(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataTable dt = LHWebApp.Services.getPlaceXQCY(clientNo).Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        //jsonHelp.AddItem("ID", dr[0].ToString());
                        jsonHelp.AddItem("Name", dr["Name"].ToString());
                        //jsonHelp.AddItem("LOACTION", dr[1].ToString());
                        //jsonHelp.AddItem("DISTRICT", dr[2].ToString());
                        //jsonHelp.AddItem("TYPE", dr[3].ToString());
                        //jsonHelp.AddItem("SIZE", dr[4].ToString());
                        jsonHelp.AddItem("LONGITUDE", dr["LONGITUDE"].ToString());
                        jsonHelp.AddItem("LATITUDE", dr["LATITUDE"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }
        //应县SelectOptions页，项目下拉列表，账户选择
        private void GetLoginInfoSelectOptions(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string clientNo = context.Request.Params["clientNo"];
            try
            {
                DataTable dt = LHWebApp.Services.GetLoginInfoYX(clientNo).Tables[0];
                JSONHelper jsonHelp = new JSONHelper();
                jsonHelp.success = true;
                jsonHelp.totlalCount = dt.Rows.Count;
                if (jsonHelp.totlalCount == 0)
                {
                    context.Response.Write("{success: true}");
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        jsonHelp.AddItem("CLIENT_NO", dr["CLIENT_NO"].ToString());

                        jsonHelp.AddItem("CLIENT_NAME", dr["CLIENT_NAME"].ToString());
                        jsonHelp.AddItem("UID", dr["UID"].ToString());
                        jsonHelp.AddItem("PWD", dr["PWD"].ToString());
                        jsonHelp.ItemOk();
                    }
                    context.Response.Write(jsonHelp.ToString());
                }
            }
            catch (Exception)
            {
                context.Response.Write("{success: false}");
            }
        }

        //2018.07.13 houruixian 百度地图经纬度矫正
        public void AdjustBaiduLongLat(List<CurrentVehicleEntity> lists)
        {
            int count = lists.Count / 100 + 1;
            string[] rawPoints = new string[count];
            for (int i = 0; i < count; i++)
            {
                rawPoints[i] = "";
            }
            List<CurrentVehicleEntity> currentLists = new List<CurrentVehicleEntity>();

            for (int i = 0; i < count; i++)
            {
                if (i < count - 1)
                {
                    for (int j = 0; j < 100; j++)
                    {
                        rawPoints[i] = rawPoints[i] + ";" + lists[j + i * 100].Lng + "," + lists[j + i * 100].Lat;
                    }
                }
                else
                {
                    for (int j = 0; j < lists.Count - 100 * (count - 1); j++)
                    {
                        rawPoints[i] = rawPoints[i] + ";" + lists[j + i * 100].Lng + "," + lists[j + i * 100].Lat;
                    }
                }
            }

            for (int i = 0; i < rawPoints.Length; i++)
            {
                rawPoints[i] = rawPoints[i].Substring(1, rawPoints[i].Length - 1);
            }

            for (int i = 0; i < count; i++)
            {
                currentLists = getBaiduLongLat(rawPoints[i]);
                if (i < count - 1)
                {
                    for (int j = 0; j < 100; j++)
                    {
                        currentVehicleList[j + i * 100].Lat = currentLists[j].Lat;
                        currentVehicleList[j + i * 100].Lng = currentLists[j].Lng;

                    }
                }
                else
                {
                    for (int j = 0; j < lists.Count - 100 * (count - 1); j++)
                    {
                        currentVehicleList[j + i * 100].Lat = currentLists[j].Lat;
                        currentVehicleList[j + i * 100].Lng = currentLists[j].Lng;
                    }
                }
            }

        }

        public List<CurrentVehicleEntity> getBaiduLongLat(string rawListStr)
        {
            List<CurrentVehicleEntity> currentLists = new List<CurrentVehicleEntity>();
            CurrentVehicleEntity currentEntity = null;

            string url = @"http://api.map.baidu.com/geoconv/v1/?coords=" + rawListStr + @"&from=1&to=5&ak=4HzsadCh4FDh1Eukq2shC3WT&output=xml";
            WebRequest request = WebRequest.Create(url);
            request.Method = "POST";
            XmlDocument xmlDoc = new XmlDocument();
            string sendData = xmlDoc.InnerXml;
            byte[] byteArray = Encoding.Default.GetBytes(sendData);

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();
            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream, System.Text.Encoding.GetEncoding("utf-8"));
            string responseXml = reader.ReadToEnd();

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(responseXml);
            string status = xml.DocumentElement.SelectSingleNode("status").InnerText;
            if (status == "0")
            {
                XmlNodeList pointnodes = xml.DocumentElement.GetElementsByTagName("point");

                foreach (XmlNode node in pointnodes)
                {
                    currentEntity = new CurrentVehicleEntity();
                    XmlNodeList XNodes = ((XmlElement)node).GetElementsByTagName("x");  //获取age子XmlElement集合  
                    if (XNodes.Count == 1)
                    {
                        currentEntity.Lng = XNodes[0].InnerText;
                    }
                    XmlNodeList YNodes = ((XmlElement)node).GetElementsByTagName("y");  //获取age子XmlElement集合  
                    if (YNodes.Count == 1)
                    {
                        currentEntity.Lat = YNodes[0].InnerText;
                    }

                    currentLists.Add(currentEntity);
                }
            }

            return currentLists;
        }

        
    }

}
